#include "logport.h"

#include "stm32f1xx.h"
#include "cmsis_os.h"

extern UART_HandleTypeDef huart2;		// From main.c
extern osMutexId mutexUartDmaHandle;    // From main.c
extern DMA_HandleTypeDef hdma_usart2_tx; // From main.c

void my_log_output(const char* log, unsigned int size)
{
    // Lock
    
    //osMutexWait(mutexUartDmaHandle, 1000);
    
	//HAL_UART_Transmit_DMA(&huart2, (uint8_t *)log, size);
    HAL_UART_Transmit(&huart2, (uint8_t *)log, size, 0xffffffff);
    
    // unlock
    //osMutexRelease(mutexUartDmaHandle);
    //osDelay(100);
    
}


void logport_init(void)
{
	elog_init();
    elog_set_fmt(ELOG_LVL_ASSERT, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_FUNC | ELOG_FMT_LINE);
    elog_set_fmt(ELOG_LVL_ERROR, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_FUNC | ELOG_FMT_LINE);
    elog_set_fmt(ELOG_LVL_WARN, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_FUNC | ELOG_FMT_LINE);
    elog_set_fmt(ELOG_LVL_INFO, ELOG_FMT_LVL | ELOG_FMT_TAG);
    elog_set_fmt(ELOG_LVL_DEBUG, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_FUNC | ELOG_FMT_LINE);
    elog_set_fmt(ELOG_LVL_VERBOSE, ELOG_FMT_LVL | ELOG_FMT_TAG);
    elog_start();
}


